﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CSharpWin_JD.CaptureImage;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_DoubleClick(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        //int length1 = 0;
        //int length2 = 0;
        Font ft = new Font("微软简隶书", 18);
        private void textBox3_TextChanged(object sender, EventArgs e)
        {

            if (this.textBox3.Text.Trim().Length >=0)
            {
                //System.Drawing.Color cl = Color.FromArgb(243, 213, 99);
                Font ft = new Font(textziti, 18);

                Bitmap bit = new Bitmap(this.panel1.Width, this.panel1.Height);//实例化一个和窗体一样大的bitmap
                Graphics g1 = Graphics.FromImage(bit);
                //g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;//质量设为最高
                //g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));
                if (this.textBox3.Text.Trim().Length > 0)
                {
                    g1.DrawImage(Image.FromFile(@"11.jpg"), 600, 20);//左边值控制左边宽带，右边值控制上下距离
                }
                for (int i = 0; i < this.textBox3.Text.Trim().Length; i++)
                {
                    g1.DrawImage(Image.FromFile(@"33.jpg"), 600, 56 + 61 * (i) + 20);
                    g1.DrawString(this.textBox3.Text.Trim()[i].ToString(), ft, Brushes.Black, 635f, 56 + 61 * (i) + 20);
                }

                if (this.textBox3.Text.Trim().Length > 0)
                {
                    g1.DrawImage(Image.FromFile(@"22.jpg"), 600, 20 + 56 + 61 * (this.textBox3.Text.Trim().Length));
                }
               
                if (this.textBox4.Text.Trim().Length > 0)
                {
                    g1.DrawImage(Image.FromFile(@"11.jpg"), 50, 20);//左边值控制左边宽带，右边值控制上下距离
                }
                for (int i = 0; i < this.textBox4.Text.Trim().Length; i++)
                {
                    g1.DrawImage(Image.FromFile(@"33.jpg"), 50, 56 + 61 * (i) + 20);
                    g1.DrawString(this.textBox4.Text.Trim()[i].ToString(), ft, Brushes.Black, 85f, 56 + 61 * (i) + 20);
                }

                if (this.textBox4.Text.Trim().Length > 0)
                {
                    g1.DrawImage(Image.FromFile(@"22.jpg"), 50, 20 + 56 + 61 * (this.textBox4.Text.Trim().Length));
                }
                if (this.button3.Text == "竖福字图")
                {
                    //这个是竖着写
                    if (this.textBox5.Text.Trim().Length > 0)
                    {
                        g1.DrawImage(Image.FromFile(this.button3.Text + ".jpg"), 240, 160);//左边值控制左边宽带，右边值控制上下距离
                    }
                    // Font ft = new Font("隶书", 28);
                    for (int i = 0; i < this.textBox5.Text.Trim().Length; i++)
                    {
                        g1.DrawString(this.textBox5.Text.Trim()[i].ToString(), ft, Brushes.Black, 350f, 100 + 61 * (i) + 120);
                    }
                }
                else
                {

                    ////这个是横着写
                    if (this.textBox5.Text.Trim().Length > 0)
                    {
                        g1.DrawImage(Image.FromFile(this.button3.Text + ".jpg"), 165, 160);//左边值控制左边宽带，右边值控制上下距离
                    }
                    // Font ft = new Font("隶书", 28);
                    for (int i = 0; i < this.textBox5.Text.Trim().Length; i++)
                    {
                        g1.DrawString(this.textBox5.Text.Trim()[i].ToString(), ft, Brushes.Black, 420 + this.pictureBox1.Width - (i) * 50, 250 + this.pictureBox1.Width);
                    }
                }


                this.panel1.BackgroundImage = bit;
            }







        }
       
        private void textBox4_TextChanged(object sender, EventArgs e)
        {

            if (this.textBox3.Text.Trim().Length >= 0)
            {
                //System.Drawing.Color cl = Color.FromArgb(243, 213, 99);
                Font ft = new Font(textziti, 18);

                Bitmap bit = new Bitmap(this.panel1.Width, this.panel1.Height);//实例化一个和窗体一样大的bitmap
                Graphics g1 = Graphics.FromImage(bit);
                //g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;//质量设为最高
                //g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));
                if (this.textBox3.Text.Trim().Length > 0)
                {
                    g1.DrawImage(Image.FromFile(@"11.jpg"), 600, 20);//左边值控制左边宽带，右边值控制上下距离
                }
                for (int i = 0; i < this.textBox3.Text.Trim().Length; i++)
                {
                    g1.DrawImage(Image.FromFile(@"33.jpg"), 600, 56 + 61 * (i) + 20);
                    g1.DrawString(this.textBox3.Text.Trim()[i].ToString(), ft, Brushes.Black, 635f, 56 + 61 * (i) + 20);
                }

                if (this.textBox3.Text.Trim().Length > 0)
                {
                    g1.DrawImage(Image.FromFile(@"22.jpg"), 600, 20 + 56 + 61 * (this.textBox3.Text.Trim().Length));
                }

                if (this.textBox4.Text.Trim().Length > 0)
                {
                    g1.DrawImage(Image.FromFile(@"11.jpg"), 50, 20);//左边值控制左边宽带，右边值控制上下距离
                }
                for (int i = 0; i < this.textBox4.Text.Trim().Length; i++)
                {
                    g1.DrawImage(Image.FromFile(@"33.jpg"), 50, 56 + 61 * (i) + 20);
                    g1.DrawString(this.textBox4.Text.Trim()[i].ToString(), ft, Brushes.Black, 85f, 56 + 61 * (i) + 20);
                }

                if (this.textBox4.Text.Trim().Length > 0)
                {
                    g1.DrawImage(Image.FromFile(@"22.jpg"), 50, 20 + 56 + 61 * (this.textBox4.Text.Trim().Length));
                }
                if (this.button3.Text == "竖福字图")
                {
                    //这个是竖着写
                    if (this.textBox5.Text.Trim().Length > 0)
                    {
                        g1.DrawImage(Image.FromFile(this.button3.Text + ".jpg"), 240, 160);//左边值控制左边宽带，右边值控制上下距离
                    }
                    // Font ft = new Font("隶书", 28);
                    for (int i = 0; i < this.textBox5.Text.Trim().Length; i++)
                    {
                        g1.DrawString(this.textBox5.Text.Trim()[i].ToString(), ft, Brushes.Black, 350f, 100 + 61 * (i) + 120);
                    }
                }
                else
                {

                    ////这个是横着写
                    if (this.textBox5.Text.Trim().Length > 0)
                    {
                        g1.DrawImage(Image.FromFile(this.button3.Text + ".jpg"), 165, 160);//左边值控制左边宽带，右边值控制上下距离
                    }
                    // Font ft = new Font("隶书", 28);
                    for (int i = 0; i < this.textBox5.Text.Trim().Length; i++)
                    {
                        g1.DrawString(this.textBox5.Text.Trim()[i].ToString(), ft, Brushes.Black, 420 + this.pictureBox1.Width - (i) * 50, 250 + this.pictureBox1.Width);
                    }
                }


                this.panel1.BackgroundImage = bit;
            }
            //System.Drawing.Color cl = Color.FromArgb(243, 213, 99);
          
            //if (this.textBox4.Text.Trim().Length > length2)
            //{
               
            //    g.DrawImage(Image.FromFile(@"11.jpg"), 50, 20);//左边值控制左边宽带，右边值控制上下距离
            //    for (int i = 0; i < this.textBox4.Text.Trim().Length; i++)
            //    {
            //        g.DrawImage(Image.FromFile(@"33.jpg"), 50, 56 + 61 * (i) + 20);
            //        g.DrawString(this.textBox4.Text.Trim()[i].ToString(), ft, Brushes.Black, 85f, 56 + 61 * (i) + 20);
            //    }
            //    g.DrawImage(Image.FromFile(@"22.jpg"), 50, 20 + 56 + 61 * (this.textBox4.Text.Trim().Length));
            //}
            //else if(this.textBox4.Text.Trim().Length < length2)
            //{
                 
               
               
            //    g.DrawImage(Image.FromFile(@"11.jpg"), 50, 20);//左边值控制左边宽带，右边值控制上下距离
            //    for (int i = 0; i < this.textBox4.Text.Trim().Length; i++)
            //    {
            //        g.DrawImage(Image.FromFile(@"33.jpg"), 50, 56 + 61 * (i) + 20);
            //        g.DrawString(this.textBox4.Text.Trim()[i].ToString(), ft, Brushes.Black, 85f, 56 + 61 * (i) + 20);
            //    }
            //    g.DrawImage(Image.FromFile(@"22.jpg"), 50, 20 + 56 + 61 * (this.textBox4.Text.Trim().Length));
                
            //}
        
            //length2 = this.textBox4.Text.Trim().Length;

        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {
            if (this.textBox3.Text.Trim().Length >= 0)
            {
                //System.Drawing.Color cl = Color.FromArgb(243, 213, 99);
                Font ft = new Font(textziti, 18);

                Bitmap bit = new Bitmap(this.panel1.Width, this.panel1.Height);//实例化一个和窗体一样大的bitmap
                Graphics g1 = Graphics.FromImage(bit);
                //g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;//质量设为最高
                //g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));
                if (this.textBox3.Text.Trim().Length > 0)
                {
                    g1.DrawImage(Image.FromFile(@"11.jpg"), 600, 20);//左边值控制左边宽带，右边值控制上下距离
                }
                for (int i = 0; i < this.textBox3.Text.Trim().Length; i++)
                {
                    g1.DrawImage(Image.FromFile(@"33.jpg"), 600, 56 + 61 * (i) + 20);
                    g1.DrawString(this.textBox3.Text.Trim()[i].ToString(), ft, Brushes.Black, 635f, 56 + 61 * (i) + 20);
                }

                if (this.textBox3.Text.Trim().Length > 0)
                {
                    g1.DrawImage(Image.FromFile(@"22.jpg"), 600, 20 + 56 + 61 * (this.textBox3.Text.Trim().Length));
                }

                if (this.textBox4.Text.Trim().Length > 0)
                {
                    g1.DrawImage(Image.FromFile(@"11.jpg"), 50, 20);//左边值控制左边宽带，右边值控制上下距离
                }
                for (int i = 0; i < this.textBox4.Text.Trim().Length; i++)
                {
                    g1.DrawImage(Image.FromFile(@"33.jpg"), 50, 56 + 61 * (i) + 20);
                    g1.DrawString(this.textBox4.Text.Trim()[i].ToString(), ft, Brushes.Black, 85f, 56 + 61 * (i) + 20);
                }

                if (this.textBox4.Text.Trim().Length > 0)
                {
                    g1.DrawImage(Image.FromFile(@"22.jpg"), 50, 20 + 56 + 61 * (this.textBox4.Text.Trim().Length));

                }


                if (this.button3.Text == "竖福字图")
                {
                    //这个是竖着写
                    if (this.textBox5.Text.Trim().Length > 0)
                    {
                        g1.DrawImage(Image.FromFile(this.button3.Text + ".jpg"), 240, 160);//左边值控制左边宽带，右边值控制上下距离
                    }
                  
                    for (int i = 0; i < this.textBox5.Text.Trim().Length; i++)
                    {
                        g1.DrawString(this.textBox5.Text.Trim()[i].ToString(), ft, Brushes.Black, 350f, 100 + 61 * (i) + 120);
                    }
                }
                else
                {

                    ////这个是横着写
                    if (this.textBox5.Text.Trim().Length > 0)
                    {
                        g1.DrawImage(Image.FromFile(this.button3.Text + ".jpg"), 165, 160);//左边值控制左边宽带，右边值控制上下距离
                    }
                   // Font ft = new Font("隶书", 28);
                    for (int i = 0; i < this.textBox5.Text.Trim().Length; i++)
                    {
                        g1.DrawString(this.textBox5.Text.Trim()[i].ToString(), ft, Brushes.Black, 420 + this.pictureBox1.Width - (i) * 50, 250 + this.pictureBox1.Width);
                    }
                }

                //if (this.textBox5.Text.Trim().Length > 0)
                //{
                //    g1.DrawImage(Image.FromFile(this.button3.Text + ".jpg"), 165, 160);//左边值控制左边宽带，右边值控制上下距离
                //}
                ////Font ft = new Font("微软简隶书", 28);
                //for (int i = 0; i < this.textBox5.Text.Trim().Length; i++)
                //{
                //    g1.DrawString(this.textBox5.Text.Trim()[i].ToString(), ft, Brushes.Black, 420 + this.pictureBox1.Width - (i) * 50, 250 + this.pictureBox1.Width);
                //}

                this.panel1.BackgroundImage = bit;
            }
        }
        
        
        
        private void Form1_Load(object sender, EventArgs e)
        {
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
            SetStyle(ControlStyles.DoubleBuffer, true);
         
            
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            this.Refresh();
        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            formPoint = this.Location;

            // 获取鼠标光标的位置（屏幕坐标）  
            mousePoint = Control.MousePosition;
        }
        // 窗体的屏幕坐标  
        Point formPoint;

        // 鼠标光标的屏幕坐标  
        Point mousePoint;
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                //获取鼠标移动时的屏幕坐标  
                Point mousePos = Control.MousePosition;

                //改变窗体位置  
                this.Location = new Point(formPoint.X + mousePos.X - mousePoint.X,
                                          formPoint.Y + mousePos.Y - mousePoint.Y);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //this.textBox3.Text = "";
            //this.textBox4.Text = "";
            //this.textBox5.Text = "";
            //System.Drawing.Color cl = Color.FromArgb(243, 213, 99);
            //g.Clear(cl);
        }
       
        private void button3_Click(object sender, EventArgs e)
        {
            if(this.button3.Text == "横福字图")
            {
               
                this.button3.Text = "竖福字图";
            }
            else
            {
                
                this.button3.Text = "横福字图";
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            CaptureImageTool capture = new CaptureImageTool();
            //capture.SelectCursor = new Cursor(Properties.Resources.Arrow_M.Handle); 
            if (capture.ShowDialog() == DialogResult.OK)
            {
                Image image = capture.Image;
                //pictureBox2.Width = image.Width;
                //pictureBox2.Height = image.Height;
                pictureBox2.BackgroundImage = image;
               
               
            }
        }
        string textziti = "微软简隶书";
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.Items != null && comboBox1.Items.Count > 0 && comboBox1.SelectedItem != null)
            {
                textziti = (string)(comboBox1.SelectedItem);
             
            }
        }
    }
}
